if(!dojo._hasResource["mydojo.NumberTextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["mydojo.NumberTextBox"] = true;
dojo.provide("mydojo.NumberTextBox");
dojo.require("dijit.form.NumberTextBox");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dojo.number");


dojo.declare(
	"mydojo.NumberTextBox",
	[dijit.form.RangeBoundTextBox,dijit.form.NumberTextBoxMixin],
	{
	// summary:
		//		A validating, serializable, range-bound text box.
		// constraints object: min, max, places
			// summary:
		//		A mixin for all number textboxes
		
   _parseInfo : function(/*Object?*/options){
   
	options = options || {};
	var locale = dojo.i18n.normalizeLocale(options.locale);
	var bundle = dojo.i18n.getLocalization("dojo.cldr", "number", locale);
	var pattern = options.pattern || bundle[(options.type || "decimal") + "Format"];
//TODO: memoize?
	var group = bundle.group;
	var decimal = bundle.decimal;
	var factor = 1;

	if(pattern.indexOf('%') != -1){
		factor /= 100;
	}else if(pattern.indexOf('\u2030') != -1){
		factor /= 1000; // per mille
	}else{
		var isCurrency = pattern.indexOf('\u00a4') != -1;
		if(isCurrency){
			group = bundle.currencyGroup || group;
			decimal = bundle.currencyDecimal || decimal;
		}
	}

	//TODO: handle quoted escapes
	var patternList = pattern.split(';');
	if(patternList.length == 1){
		patternList.push("-" + patternList[0]);
	}

	var re = dojo.regexp.buildGroupRE(patternList, function(pattern){
		pattern = "(?:"+dojo.regexp.escapeString(pattern, '.')+")";
		return pattern.replace(dojo.number._numberPatternRE, function(format){
			var flags = {
				signed: false,
				separator: options.strict ? group : [group,""],
				fractional: options.fractional,
				decimal: decimal,
				exponent: false};
			var parts = format.split('.');
			var places = options.places;
			if(parts.length == 1 || places === 0){flags.fractional = false;}
			else{
				if(places === undefined){ places = parts[1].lastIndexOf('0')+1; }
				if(places && options.fractional == undefined){flags.fractional = true;} // required fractional, unless otherwise specified
				if(!options.places && (places < parts[1].length)){ places += "," + parts[1].length; }
				flags.places = places;
			}
			var groups = parts[0].split(',');
			if(groups.length>1){
				flags.groupSize = groups.pop().length;
				if(groups.length>1){
					flags.groupSize2 = groups.pop().length;
				}
			}
			var res = function(flags){
  	// summary:
  	//		Builds a regular expression to match a real number in exponential
  	//		notation
  	// flags:
  	//		An object
  
  	// assign default values to missing paramters
  	flags = flags || {};
  	if(typeof flags.places == "undefined"){ flags.places = Infinity; }
  	if(typeof flags.decimal != "string"){ flags.decimal = "."; }
  	if(typeof flags.fractional == "undefined" || /^0/.test(flags.places)){ flags.fractional = [true, false]; }
  	if(typeof flags.exponent == "undefined"){ flags.exponent = [true, false]; }
  	if(typeof flags.eSigned == "undefined"){ flags.eSigned = [true, false]; }
  
  	// integer RE
  	var integerRE = dojo.number._integerRegexp(flags);
  //alert("integerRE:"+integerRE);
  	// decimal RE
  	var decimalRE = dojo.regexp.buildGroupRE(flags.fractional,
  		function(q){
  			var re = "";
  			if(q && (flags.places!==0)){
  				re = "\\" + flags.decimal;
  				if(flags.places == Infinity){ 
  					re = "(?:" + re + "\\d+)?"; 
  				}else{
  					re = "(.\\d{0," + flags.places + "})?"; 
  					//re += "\\d{" + flags.places + "}"; 
  				}
  			}
  			return re;
  		},true);
  //alert("decimalRE:"+decimalRE);
  	// exponent RE
  	var exponentRE = dojo.regexp.buildGroupRE(flags.exponent,
  		function(q){ 
  			if(q){ return "([eE]" + dojo.number._integerRegexp({ signed: flags.eSigned}) + ")"; }
  			return ""; 
  		}
  	);

  	// real number RE
  	var realRE = integerRE + decimalRE;
  	// allow for decimals without integers, e.g. .25
  	if(decimalRE){realRE = "(?:(?:"+ realRE + ")|(?:" + decimalRE + "))";}
  	//alert(realRE + exponentRE);
  	return realRE + exponentRE; // String
  };
      return "("+ res +")";
		});
	}, true);

	if(isCurrency){
		// substitute the currency symbol for the placeholder in the pattern
		re = re.replace(/(\s*)(\u00a4{1,3})(\s*)/g, function(match, before, target, after){
			var prop = ["symbol", "currency", "displayName"][target.length-1];
			var symbol = dojo.regexp.escapeString(options[prop] || options.currency || "");
			before = before ? "\\s" : "";
			after = after ? "\\s" : "";
			if(!options.strict){
				if(before){before += "*";}
				if(after){after += "*";}
				return "(?:"+before+symbol+after+")?";
			}
			return before+symbol+after;
		});
	}

  //TODO: substitute localized sign/percent/permille/etc.?

  	// normalize whitespace and return
  	return {regexp: re.replace(/[\xa0 ]/g, "[\\s\\xa0]"), group: group, decimal: decimal, factor: factor}; // Object
  },
    
	regExpGen:  function(/*dojo.number.__RegexpOptions?*/options){
	//	summary:
	//		Builds the regular needed to parse a number
	//	description:
	//		Returns regular expression with positive and negative match, group
	//		and decimal separators
	 return this._parseInfo(options).regexp; // String
  },
  
  parse: function(/*String*/expression, /*dojo.number.__ParseOptions?*/options){
	// summary:
	//		Convert a properly formatted string to a primitive Number, using
	//		locale-specific settings.
	// description:
	//		Create a Number from a string using a known localized pattern.
	//		Formatting patterns are chosen appropriate to the locale
	//		and follow the syntax described by
	//		[unicode.org TR35](http://www.unicode.org/reports/tr35/#Number_Format_Patterns)
	// expression:
	//		A string representation of a Number
	var info = this._parseInfo(options);
	var results = (new RegExp("^"+info.regexp+"$")).exec(expression);
	if(!results){
		return NaN; //NaN
	}
	var absoluteMatch = results[1]; // match for the positive expression
	if(!results[1]){
		if(!results[2]){
			return NaN; //NaN
		}
		// matched the negative pattern
		absoluteMatch =results[2];
		info.factor *= -1;
	}

	// Transform it to something Javascript can parse as a number.  Normalize
	// decimal point and strip out group separators or alternate forms of whitespace
	absoluteMatch = absoluteMatch.
		replace(new RegExp("["+info.group + "\\s\\xa0"+"]", "g"), "").
		replace(info.decimal, ".");
	// Adjust for negative sign, percent, etc. as necessary
	return Number(absoluteMatch) * info.factor; //Number
},
  
  
	value: 0
	});

}






